package www.openteam.com.workorder;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.ArrayList;

import www.openteam.com.R;
import www.openteam.com.bean.PDistrubition;

/**
 * Created by kylin on 2017/5/15.
 */

public class ZZWorkAdapter extends  RecyclerView.Adapter<RecyclerView.ViewHolder> {

    /**
     * 产品进度适配器
     */
    private static final String TAG = "ProAdapter";
    private LayoutInflater mLayoutInflater;
    private Context context;
    private ArrayList<PDistrubition.DataBeanX.DataBean> mSortedList;
    private StringBuffer sb = new StringBuffer();



    public ZZWorkAdapter(Context context) {
        mLayoutInflater = LayoutInflater.from(context);
        mSortedList =new ArrayList<>();
    }

    public void addItems(ArrayList<PDistrubition.DataBeanX.DataBean> list) {
        for (PDistrubition.DataBeanX.DataBean item : list) {
            mSortedList.add(item);
            notifyDataSetChanged();
        }
    }

    public void addContext(Context context){
        this.context=context;
    }

    public void deleteItems(ArrayList<PDistrubition.DataBeanX.DataBean> items) {
        for (PDistrubition.DataBeanX.DataBean item : items) {
            mSortedList.remove(item);
            notifyDataSetChanged();
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        Log.d(TAG, "DataAdapter: 3");
        return new ZZWorkAdapter.WorkViewHolder(mLayoutInflater.inflate(R.layout.wo_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    //    final MyViewHolder viewHolder = (MyViewHolder) holder;
      //  viewHolder.content.setText(mList.get(position));

        Log.d(TAG, "onBindViewHolder: "+mSortedList.get(position).getCode());


        ((WorkViewHolder) holder).et_work_id.setText(mSortedList.get(position).getCode());
        ((WorkViewHolder) holder).et_work_name.setText(mSortedList.get(position).getName());
        ((WorkViewHolder) holder).et_work_job.setText(mSortedList.get(position).getJob());



    }

    @Override
    public int getItemCount() {
        return mSortedList.size() ;
    }

    public void removeItem(int position) {
        mSortedList.remove(mSortedList.get(position));
        notifyDataSetChanged();
    }

    public void addItem(PDistrubition.DataBeanX.DataBean pd) {
        mSortedList.add(pd);
        notifyDataSetChanged();

    }


    public static class WorkViewHolder extends RecyclerView.ViewHolder {

        public LinearLayout wo_item_pr;
        public TextView et_work_id;
        public TextView item_delete;
        public   TextView et_work_name;
        public   TextView et_work_job;

        public WorkViewHolder(View itemView) {
            super(itemView);
//            Log.d(TAG, "DataAdapter: 5");
            wo_item_pr = (LinearLayout) itemView.findViewById(R.id.wo_item_pr);
            et_work_id= (TextView) itemView.findViewById(R.id.et_work_id);
            et_work_name = (TextView) itemView.findViewById(R.id.et_work_name);
            et_work_job= (TextView) itemView.findViewById(R.id.et_work_job);
            item_delete= (TextView) itemView.findViewById(R.id.item_delete);

        }
    }




}